using System.Net.Http;
using System.Text;
using Newtonsoft.Json;

namespace Comteck.Winforms.Json {
  /// <summary>
  /// json content
  /// </summary>
  public class JsonContent : StringContent {
    private static JsonSerializerSettings defaultSettings;

    /// <summary>
    /// 
    /// </summary>
    static JsonContent() {
      defaultSettings = new JsonSerializerSettings();
      defaultSettings.Converters.Add(new DateOnlyConverter());
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="value"></param>
    public JsonContent(object value) : this(value, defaultSettings) {
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="value"></param>
    /// <param name="settings"></param>
    public JsonContent(object value, JsonSerializerSettings settings) :
      base(JsonConvert.SerializeObject(value, Formatting.None, settings),
        encoding: Encoding.UTF8,
        mediaType: ComteckConstants.CONTENTTYPE_JSON) {
    }
  }
}
